#pragma once

#include "WAsyncHttpClient.h"
#include "WSyncHttpClient.h"
#include <stdio.h>

class HttpClientExample
{
public:
    HttpClientExample();
    virtual ~HttpClientExample();

    void testSyncRequest(const std::string& url, const HttpClientReqMsg& reqMsg);
    void testSyncDownloadFile(std::string url, const HttpClientReqMsg &reqMsg);
    void testAsyncRequest(std::string url, const HttpClientReqMsg& reqMsg);
    void testAsyncDownloadFile(std::string url, const HttpClientReqMsg &reqMsg);
    void run();

private:
    WSyncHttpClient *_syncHttpClient = nullptr;
    WAsyncHttpClient *_asyncHttpClient = nullptr;
    int64_t _fileId = 0;
    std::map<int64_t, FILE*> _fileIdMap;

    void handleAsyncReqCb(std::shared_ptr<HttpClientRspMsg> &rspMsg);
    void handleAsyncDownloadFileCb(int64_t fileId, std::shared_ptr<HttpClientRspMsg> &rspMsg);
    void handleSyncDownloadFileCb(int64_t fileId, std::shared_ptr<HttpClientRspMsg> &rspMsg);
};

